<?php
/**
 * Created by PhpStorm.
 * User: 庆金
 * Date: 2019-12-21
 * Time: 22:41
 * http结合redis小案例
 */
const REDIS_SERVER_HOST = "127.0.0.1";
const REDIS_SERVER_PORT = 6379;
$http = new swoole_http_server('0.0.0.0',8811);
$http->on("request",function ($request,$response){
    $redis = new Swoole\Coroutine\Redis();
    $redis->connect(REDIS_SERVER_HOST,REDIS_SERVER_PORT);
    $value = $redis->get($request->get['a']);
    $response->header("Content-Type",'text/plain');
    $response->end($value);
});
$http->start();

//
//go(function (){
//    $redis = new Swoole\Coroutine\Redis();
//    $redis->connect(REDIS_SERVER_HOST,REDIS_SERVER_PORT);
//    $redis->setDefer();
//    $redis->set("key1","value");
//
//    $redis2 = new Swoole\Coroutine\Redis();
//    $redis2->connect(REDIS_SERVER_HOST,REDIS_SERVER_PORT);
//    $redis2->setDefer();
//    $redis2->get("key1");
//    $result1 = $redis->recv();
//    $result2 = $redis2->recv();
//    var_dump($result1,$result2);
//});